package com.right.health.app.ui.household.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.magic.basic.adapter.BaseAbsAdapter;
import com.right.health.app.R;
import com.right.health.app.bean.BloodPressureResponse;

/*
 * Created by hopeliao on 2019-10-02
 *
 */
public class BloodPressureListAdapter extends BaseAbsAdapter<BloodPressureResponse.BloodPressureInfo> {

    private String format,format1;

    public BloodPressureListAdapter(Context context) {
        super(context);

        format = "%s/%smmHg";
        format1= "%s次/分";
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView == null) {
            convertView = mInflater.inflate(R.layout.blood_pressure_list_item, null);
            viewHolder = new ViewHolder();

            viewHolder.timeTv = (TextView) convertView.findViewById(R.id.tv_time);
            viewHolder.valueTv = (TextView) convertView.findViewById(R.id.tv_value);
            viewHolder.stateTv = (TextView) convertView.findViewById(R.id.state_tv) ;
            viewHolder.pulseTv = (TextView) convertView.findViewById(R.id.tv_pulse);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        BloodPressureResponse.BloodPressureInfo info = mDataSource.get(position);

        viewHolder.valueTv.setText(String.format(format, info.highpressure, info.lowvoltage));
        viewHolder.timeTv.setText(info.createtime);
        info.refreshState(viewHolder.stateTv);

        viewHolder.pulseTv.setText(String.format(format1, info.pulse));
        return convertView;
    }

    private class ViewHolder {
        private TextView timeTv, valueTv;
        private TextView stateTv, pulseTv;
    }
}
